package pl.edu.agh.hypergraph;

import java.util.HashMap;
import java.util.UUID;

import pl.edu.agh.solid.Solid;

import edu.uci.ics.jung.graph.UndirectedSparseMultigraph;

public class CFAH extends UndirectedSparseMultigraph<CV, CE> {

	private static final long serialVersionUID = 5152971189989764607L;
	private HashMap<UUID, CV> id2v = new HashMap<>();

	@Override
	public boolean addVertex(CV vertex) {

		id2v.put(vertex.solidId, vertex);

		return super.addVertex(vertex);
	}

	
	

	public boolean addVertex(Solid s) {

		CV vertex = new CV(new FAH(s));
		return this.addVertex(vertex);
	}
	
	
	@Override
	public boolean removeVertex(CV vertex) {
		id2v.remove(vertex.solidId);
		return super.removeVertex(vertex);
	}

	public void addEdge(Solid x, Solid y, Object attr) {

		if (!id2v.containsKey(x.getId())) {

			this.addVertex(new CV(new FAH(x)));
		}

		if (!id2v.containsKey(y.getId())) {

			this.addVertex(new CV(new FAH(y)));
		}

		CV v1 = id2v.get(x.getId());
		CV v2 = id2v.get(y.getId());

		if (findEdge(v1, v2) == null)
			addEdge(new CE(attr), v1, v2);

	}

	public CFAH() {
		super();

	}

}
